<template>
  <view>
    <view class="loadinggif" v-if="isloading">
      <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/loading.gif"></image>
    </view>
    <block v-if="!isloading">
      <view class="xgsptitle" :style="'background:' + color">
        <image @tap="back" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jiantou.png"></image>
        <view class="flex-grow-1">{{ store.name }}</view>
      </view>
      <view class="dclb flex-row">
        <scroll-view
          class="leftsv flex-col"
          :scrollY="true"
          style="height: 86vh"
        >
          <view
            @tap="selectMenu"
            :class="
              'menu-item border-1px ' +
              (index == catalogSelect ? 'active' : 'selsect')
            "
            :data-id="item.id"
            :data-item-index="index"
            v-if="item.goods.length != 0"
            v-for="(item, index) in dishes"
            :key="item.value"
          >
            <!-- <view class="goods_border" :style="'background:' + color" v-if="index == catalogSelect"></view> -->

            <view class="text">
              {{ item.type_name }}
            </view>
          </view>
        </scroll-view>
        <scroll-view
          class="rightsv flex-grow-1 flex-col"
          :scrollY="true"
          style="height: 86vh"
        >
          <block v-if="!cpjzz">
            <view class="youhui">
              <view class="yh">
                {{ dishes[catalogSelect].type_name }}
                <text>({{ dishes[catalogSelect].good.length }})</text>
              </view>
            </view>
            <view
              class="cplb flex-row"
              :data-id="dishes[catalogSelect].id"
              v-for="(gooditem, goodindex) in dishes[catalogSelect].good"
              :key="goodindex"
            >
              <image
                @tap="spxqck"
                class="cpleftimg flex-grow-0"
                :data-goodid="gooditem.id"
                :data-item-index="goodindex"
                :data-parentIndex="catalogSelect"
                :src="gooditem.logo"
              ></image>

              <view class="cplbright flex-grow-1 flex-col">
                <view class="cplbright1 flex-bet">
                  <view class="cplbright1-l">{{ gooditem.name }}</view>
                  <view class="cplbright1-r" v-if="gooditem.is_zp == '1'"
                    >招牌</view
                  >
                </view>
                <view class="cplbright2 flex-bet flex-y-center">
                  <view class="gobyndsingle">{{ gooditem.content }}</view>
                </view>
                <view class="cplbright3 flex-row flex-y-center">
                  <view class="cplbright31">月销{{ gooditem.sales }}笔</view>
                </view>
                <view class="cplbright4 flex-bet">
                  <view class="cplbright4-l flex-grow-1">
                    <text>￥{{ gooditem.dn_money }}</text>
                  </view>
                  <view class="cartControl flex-grow-0">
                    <view
                      @tap.stop.prevent="ggcartdec"
                      class="cartdec"
                      v-if="gooditem.is_gg == '2' && gooditem.quantity > 0"
                    ></view>
                    <view
                      @tap.stop.prevent="cartdec"
                      class="cartdec"
                      :data-goodid="gooditem.id"
                      :data-item-index="goodindex"
                      :data-parentIndex="catalogSelect"
                      v-if="gooditem.is_gg != '2' && gooditem.quantity > 0"
                    ></view>
                    <view class="goodsnum" v-if="gooditem.quantity > 0">{{
                      gooditem.quantity
                    }}</view>
                    <view
                      @tap.stop.prevent="spggck"
                      class="xgg"
                      :data-goodid="gooditem.id"
                      :data-item-index="goodindex"
                      :data-parentIndex="catalogSelect"
                      :style="'background:' + color"
                      v-if="gooditem.is_gg == '2'"
                    >
                      选规格
                    </view>
                    <view
                      @tap.stop.prevent="cartadd"
                      class="cartadd"
                      :data-goodid="gooditem.id"
                      :data-item-index="goodindex"
                      :data-parentIndex="catalogSelect"
                      :style="'background:' + color"
                      v-if="gooditem.is_gg != '2' && gooditem.inventory != '0'"
                    ></view>
                  </view>
                  <view
                    class="xgg"
                    style="background: #cccccc"
                    v-if="gooditem.is_gg != '2' && gooditem.inventory == '0'"
                    >已售完</view
                  >
                </view>
              </view>
            </view>
          </block>
          <view class="jzz" v-if="cpjzz">
            <image
              class="Rotation"
              src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"
            ></image>
            <view>加载中...</view>
          </view>
        </scroll-view>
      </view>
      <view class="dbgwc flex-row flex-y-center" v-if="selectedindex == 0">
        <view
          @tap.stop.prevent="showcart"
          class="dbgwcl flex-row flex-y-center"
        >
          <view
            class="dbgwcl-l flex-grow-0 flex-row flex-y-center"
            v-if="cart_list.res.length == 0"
          >
            <image
              class="gwcimg"
              src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/kgwc.png"
            ></image>
          </view>
          <view class="dbgwcl-l flex-grow-0 flex-row flex-y-center" v-else>
            <image
              class="gwcimg"
              src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/fgwc.png"
            ></image>
            <view class="cart_num">{{ cart_list.num }}</view>
          </view>
          <view class="dbgwcl-r flex-grow-1">
            <view class="kname" v-if="cart_list.res.length == 0"
              >购物车是空的</view
            >
            <view class="gwcmoney" v-else>
              <text>￥{{ cart_list.money }}</text>
            </view>
          </view>
        </view>
        <block v-if="!isyy">
          <block v-if="!iskt">
            <block v-if="store.is_rest == '2' && time == 1">
              <view
                @tap="submit"
                class="dbgwcr"
                :style="'background:' + color"
                v-if="cart_list.money > 0 && cart_list.money >= start_at"
                >{{ subtext }}</view
              >
              <view class="dbgwcr" v-else>{{ subtext }}</view>
            </block>
            <view class="dbgwcr" v-else>商家暂未营业</view>
          </block>
          <view class="dbgwcr" v-else>此桌已开台</view>
        </block>
        <block v-else>
          <view
            @tap="back"
            class="dbgwcr"
            :style="'background:' + color"
            v-if="cart_list.money > 0 && cart_list.money >= start_at"
            >选好了</view
          >
        </block>
      </view>
    </block>
    <view
      @tap.stop.prevent="closecart"
      :class="'share-modal ' + (share_modal_active ? 'active' : '')"
    >
      <view class="share-modal-body">
        <view class="shangpin_bomb">
          <view class="shangpin1" :style="'border-left:10rpx solid ' + color"
            >购物车</view
          >
          <view
            @tap.stop.prevent="clear"
            class="sh_clear flex-row flex-y-center"
            v-if="cart_list.res.length > 0"
          >
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/qksj.png"></image>
            <view>清空</view>
          </view>
        </view>
        <view class="splist">
          <view
            class="dgsp flex-row flex-y-center"
            v-for="(item, index) in cart_list.res"
            :key="index"
          >
            <view class="dgspleft flex-grow-1">
              <view class="dgspleft1">{{ item.name }}</view>
              <view class="dgspleft2">{{ item.spec }}</view>
            </view>

            <view class="dgspright flex-row flex-y-center flex-grow-0">
              <view class="dgspright-l flex-grow-0">￥{{ item.money }}</view>
              <view class="cartControl flex-grow-1">
                <view
                  @tap.stop.prevent="gwcdec"
                  class="cartdec"
                  :data-goodid="item.good_id"
                  :data-id="item.id"
                  :data-num="item.num"
                ></view>
                <view class="goodsnum">{{ item.num }}</view>
                <view
                  @tap.stop.prevent="gwcadd"
                  class="cartadd"
                  :data-goodid="item.good_id"
                  :data-id="item.id"
                  :data-num="item.num"
                  :style="'background:' + color"
                ></view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view @tap="queren" class="fwxxzz" v-if="!fwxy"></view>
    <view class="fwxx" v-if="!fwxy">
      <scroll-view scrollY class="fwxxbd" style="height: 700rpx">
        <view class="sjname flex-col flex-x-center flex-y-center">
          <view class="headtitle">{{ store.name }}</view>
          <view class="pfimg">
            <view class="kximg">
              <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/i-star.png"></image>
            </view>
            <view
              class="sximg"
              :style="'width: ' + store.score * 20 + '%'"
              v-if="store.score != '0'"
            >
              <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/i-stars.png"></image>
            </view>
            <view class="sximg" v-else>
              <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/i-stars.png"></image>
            </view>
          </view>
        </view>
        <view class="sjgg">
          <view class="headtitle">商家公告</view>
          <view class="sjgginfo">{{ store.announcement }}</view>
        </view>
        <view class="yhxx">
          <view class="headtitle">优惠信息</view>
          <view class="yhxxmj">
            <view class="flex-row" v-if="reduction.length > 0">
              <view class="mj flex-grow-0">减</view>
              <view class="">
                <text v-for="(item, index) in reduction" :key="index"
                  >满{{ item.full }}减{{ item.reduction }},</text
                >
              </view>
            </view>
            <view class="flex-row" v-if="storeset.xyh_open == '1'">
              <view class="xyh flex-grow-0">新</view>
              <view class="">新用户下单立减{{ storeset.xyh_money }}元</view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
    <view
      @tap="gbspgg"
      @touchmove.stop.prevent="trueFun"
      class="spggzz"
      v-if="!spggtoggle"
    ></view>
    <view class="spgg" v-if="!spggtoggle">
      <view class="spggbd">
        <view class="spgg_title">{{ spname }}</view>
        <view @tap="gbspgg" class="x">
          <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/x.png"></image>
        </view>
        <view class="spgg_ggbd">
          <block v-for="(attr_group, index) in gg" :key="index">
            <view class="guige">{{ attr_group.spec_name }}：</view>

            <view class="ggcontent">
              <view
                @tap="attrClick"
                class="drawer_gg"
                :data-group-id="attr_group.spec_id"
                :data-id="item.spec_val_id"
                :style="
                  'background:' +
                  (item.checked ? color : '') +
                  ';color:' +
                  (item.checked ? '#fff' : '') +
                  ';border-color:' +
                  (item.checked ? '#fff' : '') +
                  ';'
                "
                v-for="(item, index1) in attr_group.spec_val"
                :key="index1"
              >
                {{ item.spec_val_name }}
              </view>
            </view>
          </block>
        </view>
        <view class="spgg_ft flex-bet">
          <view class="spgg_ftjg">￥{{ gginfo.dn_money }}</view>
          <view
            @tap="ggaddcart"
            class="spgg_ftjr"
            :style="'background: ' + color"
            >加入购物车</view
          >
        </view>
      </view>
    </view>
    <view @tap="gbyysj" class="yysjzz" v-if="!yysjtoggle"></view>
    <view class="yysj" v-if="!yysjtoggle">
      <view class="yysjimg">
        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/wming/wyy.png"></image>
      </view>
      <view class="fyysj">非营业时间，商户休息中</view>
      <view class="kysj">{{ store.time }}开始营业</view>
      <view class="yysjft">
        <view @tap="ckcd" class="ckcd">查看菜单</view>
        <view @tap="gdsh" class="gdsh">更多商户</view>
      </view>
    </view>
    <scroll-view class="spxqmodal" :scrollY="true" v-if="!spxqtoggle">
      <view @tap="gbspxq" class="spxqhead">
        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/spxqx.png"></image>
      </view>
      <view class="spxqimg">
        <image :src="spxqinfo.logo"></image>
        <view class="spsm" v-if="spxqinfo.content != ''"
          >商品说明：{{ spxqinfo.content }}</view
        >
      </view>
      <view class="spxx">
        <view class="cplbright1 flex-bet">
          <view class="cplbright1-l">{{ spxqinfo.name }}</view>
          <view class="cplbright1-r" v-if="spxqinfo.is_zp == '1'">招牌</view>
        </view>
        <view
          class="cplbright3 flex-row flex-y-center"
          style="margin-top: 10rpx"
        >
          <view class="cplbright31">月销{{ spxqinfo.sales }}笔</view>
          <view class="cplbright32">库存{{ spxqinfo.inventory }}</view>
        </view>
        <view class="cplbright4 flex-bet">
          <view class="cplbright4-l flex-grow-1">
            <text>￥{{ spxqinfo.dn_money }}</text>
          </view>
          <view class="cartControl flex-grow-0">
            <view
              @tap.stop.prevent="ggcartdec"
              class="cartdec"
              v-if="
                spxqinfo.is_gg == '2' &&
                dishes[spxqinfo.catalogSelect].good[spxqinfo.goodindex]
                  .quantity > 0
              "
            ></view>
            <view
              @tap.stop.prevent="cartdec"
              class="cartdec"
              :data-goodid="spxqinfo.id"
              :data-item-index="spxqinfo.goodindex"
              :data-parentIndex="spxqinfo.catalogSelect"
              v-if="
                spxqinfo.is_gg != '2' &&
                dishes[spxqinfo.catalogSelect].good[spxqinfo.goodindex]
                  .quantity > 0
              "
            ></view>
            <view
              class="goodsnum"
              v-if="
                dishes[spxqinfo.catalogSelect].good[spxqinfo.goodindex]
                  .quantity > 0
              "
            >
              {{
                dishes[spxqinfo.catalogSelect].good[spxqinfo.goodindex].quantity
              }}
            </view>
            <view
              @tap.stop.prevent="spggck"
              class="xgg"
              :data-goodid="spxqinfo.id"
              :data-item-index="spxqinfo.goodindex"
              :data-parentIndex="spxqinfo.catalogSelect"
              :style="'background:' + color"
              v-if="spxqinfo.is_gg == '2'"
            >
              选规格
            </view>
            <view
              @tap.stop.prevent="cartadd"
              class="cartadd"
              :data-goodid="spxqinfo.id"
              :data-item-index="spxqinfo.goodindex"
              :data-parentIndex="spxqinfo.catalogSelect"
              :style="'background:' + color"
              v-if="spxqinfo.is_gg != '2' && spxqinfo.inventory != '0'"
            ></view>
          </view>
          <view
            class="xgg"
            style="background: #cccccc"
            v-if="spxqinfo.is_gg != '2' && spxqinfo.inventory == '0'"
            >已售完</view
          >
        </view>
      </view>
      <view class="spxq">商品详情</view>
      <view class="spxqv">
        <rich-text :nodes="spxqinfo.details"></rich-text>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
import gettel from '@/ymq_canyino2o/dist/gettel/index'
var app = getApp()
var util = require('../../utils/util.js')
export default {
  components: {
    cardlist,
    gettel
  },
  data() {
    return {
      isloading: true,
      store_id: '1',
      navbar: ['店内', '评价', '详情'],
      selectedindex: 0,
      catalogSelect: 0,
      share_modal_active: false,
      color: '',
      fwxy: true,
      cpjzz: true,
      spggtoggle: true,
      yysjtoggle: true,
      spxqtoggle: true,
      gg: [],
      storeyyzz: [],
      pjselectedindex: 0,
      isytpj: false,
      pagenum: 1,
      storelist: [],
      bfstorelist: [],
      mygd: false,
      jzgd: true,
      zuid: '',
      dr_id: '',
      tableid: '',
      isyy: false,
      time: 0,
      psf: '',
      reduction: '',

      store: {
        name: '',
        is_rest: '',
        score: 0,
        announcement: '',
        time: ''
      },

      storeset: {
        xyh_open: '',
        xyh_money: ''
      },

      start_at: 0,
      isfqr: false,
      userinfo: '',

      cart_list: {
        res: [],
        num: '',
        money: ''
      },

      dishes: '',
      height: '',

      spxqinfo: {
        logo: '',
        content: '',
        name: '',
        is_zp: '',
        sales: '',
        inventory: '',
        dn_money: '',
        is_gg: '',
        id: '',
        goodindex: '',
        catalogSelect: '',
        details: ''
      },

      spname: '',

      gginfo: {
        dn_money: ''
      },

      parentindex: '',
      subtext: '',
      good: [],
      id: '',
      goodindex: 0,

      gooditem: {
        id: '',
        logo: '',
        name: '',
        is_zp: '',
        content: '',
        sales: '',
        dn_money: '',
        is_gg: '',
        quantity: 0,
        inventory: ''
      },

      iskt: '',

      attr_group: {
        spec_name: '',
        spec_id: '',
        spec_val: []
      },

      quantity: 0
    }
  },
  onLoad: function (a) {
    console.log('options', a)
    app.globalData.setNavigationBarColor(this)
    this.setData({
      store_id: a.storeid,
      zuid: a.zuid,
      dr_id: a.dr_id,
      tableid: a.tableid
    })
    if ('1' == a.isyy) {
      this.setData({
        isyy: true
      })
    } else {
      this.setData({
        isyy: false
      })
    }
    var that = this
    var t = that.store_id
    var l = util.formatTime(new Date()).slice(11, 16)
    app.globalData.util.request({
      url: 'entry/wxapp/Url',
      cachetime: '0',
      success: function (n) {
        console.log(n.data)
        getApp().globalData.imgurl = n.data
        that.setData({
          url: n.data
        })
        app.globalData.util.request({
          url: 'entry/wxapp/StoreInfo',
          cachetime: '0',
          data: {
            store_id: t,
            type: 1
          },
          success: function (t) {
            console.log(t.data)
            var a = t.data.store.time
            var e = t.data.store.time2
            var o = t.data.store.time3
            var s = t.data.store.time4
            var i = t.data.store.is_rest
            console.log('当前的系统时间为' + l)
            console.log('商家的营业时间从' + a + '至' + e, o + '至' + s)
            if (1 == i) {
              that.setData({
                yysjtoggle: false
              })
              console.log('商家正在休息' + i)
            } else {
              console.log('商家正在营业' + i)
            }
            if (a < s) {
              if ((a < l && l < e) || (o < l && l < s)) {
                console.log('商家正常营业')
                that.setData({
                  time: 1
                })
              } else {
                if (l < a || (e < l && l < o)) {
                  console.log('商家还没开店呐，稍等一会儿可以吗？')
                  that.setData({
                    time: 2,
                    yysjtoggle: false
                  })
                } else {
                  if (s < l) {
                    console.log('商家以及关店啦，明天再来吧')
                    that.setData({
                      time: 3,
                      yysjtoggle: false
                    })
                  }
                }
              }
            } else {
              if (s < a) {
                if ((a < l && l < e) || (o < l && s < l) || (l < o && l < s)) {
                  console.log('商家正常营业'),
                    that.setData({
                      time: 1
                    })
                } else {
                  if (l < a || (e < l && l < o)) {
                    console.log('商家还没开店呐，稍等一会儿可以吗？'),
                      that.setData({
                        time: 2,
                        yysjtoggle: false
                      })
                  } else {
                    s < l &&
                      (console.log('商家以及关店啦，明天再来吧'),
                      that.setData({
                        time: 3,
                        yysjtoggle: false
                      }))
                  }
                }
              }
            }
            for (var d = 0; d < t.data.store.environment.length; d++) {
              t.data.store.environment[d] = n.data + t.data.store.environment[d]
            }
            for (var r = 0; r < t.data.store.yyzz.length; r++) {
              t.data.store.yyzz[r] = n.data + t.data.store.yyzz[r]
            }
            if ('' != t.data.storeset.dn_name) {
              uni.setNavigationBarTitle({
                title: t.data.storeset.dn_name
              })
              that.setData({
                navbar: [t.data.storeset.dn_name, '评价', '详情']
              })
            }
            that.setData({
              psf: t.data.psf,
              reduction: t.data.reduction,
              store: t.data.store,
              storeset: t.data.storeset,
              start_at: 0
            })
          }
        })
      }
    })
    app.globalData.getUserInfo(function (t) {
      console.log(t)
      if (t.id == a.zuid) {
        that.setData({
          isfqr: true
        })
      } else {
        that.setData({
          isfqr: false
        })
      }
      that.setData({
        userinfo: t
      })
      var s = uni.getStorageSync('users').id
      var d = that.store_id
      console.log('uid', s)
      app.globalData.util.request({
        url: 'entry/wxapp/Hot',
        cachetime: '0',
        data: {
          store_id: d,
          type: 1
        },
        success: function (t) {
          console.log(t.data)
          for (var a = 0; a < t.data.length; a++) {
            t.data[a].quantity = Number(t.data[a].quantity)
          }
          if (0 < t.data.length) {
            var e = new Array()
            var o = new Object()
            o.good = t.data
            o.type_name = '热销'
            o.id = '0'
            e.push(o)
            app.globalData.util.request({
              url: 'entry/wxapp/DishesType',
              cachetime: '0',
              data: {
                store_id: d,
                type: 1
              },
              success: function (t) {
                console.log(t.data)
                var i = e.concat(t.data)
                console.log(i)
                that.setData({
                  cpjzz: false
                })
                app.globalData.util.request({
                  url: 'entry/wxapp/MyCar',
                  cachetime: '0',
                  data: {
                    store_id: d,
                    user_id: that.isfqr ? s : that.zuid,
                    son_id: that.isfqr ? '' : s,
                    dr_id: that.isfqr ? '' : that.dr_id,
                    type: 2
                  },
                  success: function (t) {
                    console.log(t)
                    for (var a = t.data.res, e = 0; e < a.length; e++) {
                      for (var o = 0; o < i.length; o++) {
                        for (var s = 0; s < i[o].good.length; s++) {
                          if (a[e].good_id == i[o].good[s].id) {
                            i[o].good[s].quantity =
                              i[o].good[s].quantity + Number(a[e].num)
                          }
                        }
                      }
                    }
                    console.log(i)
                    that.setData({
                      cart_list: t.data,
                      dishes: i,
                      isloading: false
                    })
                    that.subText()
                  }
                })
              }
            })
          } else {
            app.globalData.util.request({
              url: 'entry/wxapp/DishesType',
              cachetime: '0',
              data: {
                store_id: d,
                type: 1
              },
              success: function (t) {
                console.log(t.data)
                var i = t.data
                app.globalData.util.request({
                  url: 'entry/wxapp/Dishes',
                  cachetime: '0',
                  data: {
                    type_id: i[0].id,
                    type: 1
                  },
                  success: function (t) {
                    console.log(t.data)
                    for (var a = 0; a < t.data.length; a++) {
                      t.data[a].quantity = Number(t.data[a].quantity)
                    }
                    i[0].good = t.data
                    that.setData({
                      cpjzz: false
                    })
                    app.globalData.util.request({
                      url: 'entry/wxapp/MyCar',
                      cachetime: '0',
                      data: {
                        store_id: d,
                        user_id: that.isfqr ? s : that.zuid,
                        son_id: that.isfqr ? '' : s,
                        dr_id: that.isfqr ? '' : that.dr_id,
                        type: 2
                      },
                      success: function (t) {
                        console.log(t)
                        for (var a = t.data.res, e = 0; e < a.length; e++) {
                          for (var o = 0; o < i.length; o++) {
                            for (var s = 0; s < i[o].good.length; s++) {
                              if (a[e].good_id == i[o].good[s].id) {
                                i[o].good[s].quantity =
                                  i[o].good[s].quantity + Number(a[e].num)
                              }
                            }
                          }
                        }
                        console.log(i)
                        that.setData({
                          cart_list: t.data,
                          dishes: i,
                          isloading: false
                        })
                        that.subText()
                      }
                    })
                  }
                })
              }
            })
          }
        }
      })
    })
    uni.getSystemInfo({
      success: function (t) {
        console.log(t)
        that.setData({
          height: t.windowHeight - 145
        })
      }
    })
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  methods: {
    back: function () {
      uni.navigateBack({
        delta: 1
      })
    },

    submit: function () {
      var t = this.userinfo
      var a = this.store_id
      var e = this.zuid
      var o = this.dr_id
      console.log(t, a, e, o, this.tableid)
      if ('' == t.img || '' == t.name) {
        uni.navigateTo({
          url: 'getdl'
        })
      } else {
        if (t.id == e) {
          uni.reLaunch({
            url: 'drdc?storeid=' + a + '&tableid=' + this.tableid
          })
        } else {
          uni.reLaunch({
            url:
              '/ymq_canyino2o/pages/smdc/sharedrdc?storeid=' +
              a +
              '&uid=' +
              e +
              '&drid=' +
              o
          })
        }
      }
    },

    lookck: function () {
      this.setData({
        fwxy: false
      })
    },

    queren: function () {
      this.setData({
        fwxy: true
      })
    },

    spxqck: function (t) {
      var a = t.currentTarget.dataset.itemIndex
      var e = t.currentTarget.dataset.parentindex
      var o = this.dishes
      var s = this.cart_list.res
      var i = t.currentTarget.dataset.goodid
      var d = this.dishes[e].good[a]
      var r = uni.getStorageSync('users').id
      var n = this.store_id
      d.goodindex = a
      d.catalogSelect = e
      console.log(o, s, a, e, i, d, r, n)
      this.setData({
        spxqinfo: d,
        spxqtoggle: false
      })
    },

    ckcd: function () {
      this.setData({
        yysjtoggle: true
      })
    },

    gdsh: function () {
      uni.navigateBack({})
    },

    gbspxq: function () {
      this.setData({
        spxqtoggle: true
      })
    },

    ggcartdec: function () {
      var that = this
      uni.showModal({
        title: '提示',
        content: '多规格商品请在购物车中删除对应的规格商品！',
        success: function (t) {
          that.setData({
            share_modal_active: true
          })
        }
      })
    },

    gwcdec: function (t) {
      var that = this
      var s = this.dishes
      var i = t.currentTarget.dataset.goodid
      var a = Number(t.currentTarget.dataset.num) - 1
      var e = t.currentTarget.dataset.id
      console.log(s, i, a, e)
      uni.showLoading({
        title: '正在加载',
        mask: true
      })
      app.globalData.util.request({
        url: 'entry/wxapp/UpdCar',
        cachetime: '0',
        data: {
          num: a,
          id: e
        },
        success: function (t) {
          console.log(t)
          if ('1' == t.data) {
            for (var a = 0; a < s.length; a++) {
              for (var e = 0; e < s[a].good.length; e++) {
                if (s[a].good[e].id == i) {
                  s[a].good[e].quantity--
                }
              }
            }
            that.setData({
              dishes: s
            })
            that.gwcreload()
          }
          if ('超出库存!' == t.data) {
            uni.showModal({
              title: '提示',
              content: '超出库存!'
            })
          }
        }
      })
    },

    gwcadd: function (t) {
      var that = this
      var s = this.dishes
      var i = t.currentTarget.dataset.goodid
      var a = Number(t.currentTarget.dataset.num) + 1
      var e = t.currentTarget.dataset.id
      console.log(s, i, a, e)
      uni.showLoading({
        title: '正在加载',
        mask: true
      })
      app.globalData.util.request({
        url: 'entry/wxapp/UpdCar',
        cachetime: '0',
        data: {
          num: a,
          id: e
        },
        success: function (t) {
          console.log(t)
          if ('1' == t.data) {
            for (var a = 0; a < s.length; a++) {
              for (var e = 0; e < s[a].good.length; e++) {
                if (s[a].good[e].id == i) {
                  s[a].good[e].quantity++
                }
              }
            }
            that.setData({
              dishes: s
            })
            that.gwcreload()
          }
          if ('超出库存!' == t.data) {
            uni.showModal({
              title: '提示',
              content: '超出库存!请选择其他商品'
            })
          }
        }
      })
    },

    cartdec: function (t) {
      var a = t.currentTarget.dataset.itemIndex
      var e = t.currentTarget.dataset.parentindex
      var o = this.dishes
      var s = this.cart_list.res
      var i = t.currentTarget.dataset.goodid
      var that = this
      var r = this.dishes[e].good[a]
      var n = uni.getStorageSync('users').id
      var c = this.store_id
      console.log(o, s, a, e, i, r, n, c)
      for (var l = 0; l < s.length; l++) {
        if (s[l].good_id == i) {
          var g = Number(s[l].num) - 1
          var u = s[l].id
          console.log(s[l], g, u)
          uni.showLoading({
            title: '正在加载',
            mask: true
          })
          app.globalData.util.request({
            url: 'entry/wxapp/UpdCar',
            cachetime: '0',
            data: {
              num: g,
              id: u
            },
            success: function (t) {
              console.log(t)
              if ('1' == t.data) {
                for (var a = 0; a < o.length; a++) {
                  for (var e = 0; e < o[a].good.length; e++) {
                    if (o[a].good[e].id == i) {
                      o[a].good[e].quantity--
                    }
                  }
                }
                that.setData({
                  dishes: o
                })
                that.gwcreload()
              }
              if ('超出库存!' == t.data) {
                uni.showModal({
                  title: '提示',
                  content: '超出库存!'
                })
              }
            }
          })
        }
      }
    },

    cartadd: function (t) {
      var a = t.currentTarget.dataset.itemIndex
      var e = t.currentTarget.dataset.parentindex
      var o = this.dishes
      var s = t.currentTarget.dataset.goodid
      var that = this
      var d = this.dishes[e].good[a]
      var r = uni.getStorageSync('users').id
      var n = this.store_id
      console.log(a, e, s, d, r, n)
      uni.showLoading({
        title: '正在加载',
        mask: true
      })
      app.globalData.util.request({
        url: 'entry/wxapp/AddCar',
        cachetime: '0',
        data: {
          money: d.dn_money,
          good_id: s,
          store_id: n,
          user_id: that.isfqr ? r : that.zuid,
          son_id: that.isfqr ? '' : r,
          dr_id: that.isfqr ? '' : that.dr_id,
          num: 1,
          spec: '',
          combination_id: '',
          box_money: d.box_money,
          type: 2
        },
        success: function (t) {
          console.log(t)
          if ('1' == t.data) {
            for (var a = 0; a < o.length; a++) {
              for (var e = 0; e < o[a].good.length; e++) {
                if (o[a].good[e].id == s) {
                  o[a].good[e].quantity++
                }
              }
            }
            that.setData({
              dishes: o
            })
            console.log(o)
            that.gwcreload()
          }
          if ('超出库存!' == t.data) {
            uni.showModal({
              title: '提示',
              content: '库存不足!请重新选择'
            })
          }
        }
      })
    },

    spggck: function (t) {
      var n = t.currentTarget.dataset.itemIndex
      var c = t.currentTarget.dataset.parentindex
      var l = t.currentTarget.dataset.goodid
      var that = this
      console.log(n, c, l)
      app.globalData.util.request({
        url: 'entry/wxapp/GoodInfo',
        cachetime: '0',
        data: {
          good_id: l
        },
        success: function (t) {
          console.log(t.data)
          var a = t.data.spec
          var e = t.data.name
          for (var o in a) {
            for (var s in a[o].spec_val) {
              a[o].spec_val[s].checked = 0 == s
            }
          }
          that.setData({
            gg: a,
            spname: e
          })
          console.log(a)
          var i = []
          var d = true
          for (var o in a) {
            var r = false
            for (var s in a[o].spec_val) {
              if (a[o].spec_val[s].checked) {
                i.push(a[o].spec_val[s].spec_val_name)
                r = true
                break
              }
            }
            if (!r) {
              d = false
              break
            }
          }
          console.log(l, i, i.toString())
          if (d) {
            uni.showLoading({
              title: '正在加载',
              mask: true
            })
            app.globalData.util.request({
              url: 'entry/wxapp/GgZh',
              cachetime: '0',
              data: {
                combination: i.toString(),
                good_id: l
              },
              success: function (t) {
                console.log(t)
                that.setData({
                  spggtoggle: false,
                  gginfo: t.data,
                  itemIndex: n,
                  parentindex: c
                })
              }
            })
          }
        }
      })
    },

    attrClick: function (t) {
      var that = this
      var e = this.gginfo.good_id
      var o = t.target.dataset.groupId
      var s = t.target.dataset.id
      var i = that.gg
      for (var d in (console.log(o, s, i), i)) {
        if (i[d].spec_id == o) {
          for (var r in i[d].spec_val) {
            if (i[d].spec_val[r].spec_val_id == s) {
              i[d].spec_val[r].checked = true
            } else {
              i[d].spec_val[r].checked = false
            }
          }
        }
      }
      that.setData({
        gg: i
      })
      var n = []
      var c = true
      for (var d in i) {
        var l = false
        for (var r in i[d].spec_val) {
          if (i[d].spec_val[r].checked) {
            n.push(i[d].spec_val[r].spec_val_name)
            l = true
            break
          }
        }
        if (!l) {
          c = false
          break
        }
      }
      console.log(e, n, n.toString())
      if (c) {
        uni.showLoading({
          title: '正在加载',
          mask: true
        })
        app.globalData.util.request({
          url: 'entry/wxapp/GgZh',
          cachetime: '0',
          data: {
            combination: n.toString(),
            good_id: e
          },
          success: function (t) {
            console.log(t)
            that.setData({
              gginfo: t.data
            })
          }
        })
      }
    },

    ggaddcart: function () {
      var t = this.itemIndex
      var a = this.parentindex
      var o = this.dishes
      var that = this
      var i = this.gginfo
      var e = uni.getStorageSync('users').id
      var d = this.gg
      var r = this.store_id
      var n = []
      var c = true
      for (var l in d) {
        var g = false
        for (var u in d[l].spec_val) {
          if (d[l].spec_val[u].checked) {
            n.push(d[l].spec_name + ':' + d[l].spec_val[u].spec_val_name)
            g = true
            break
          }
        }
        if (!g) {
          c = false
          break
        }
      }
      console.log('加入购物车', t, a, o, i, e, r, d, n, n.toString())
      if (c) {
        uni.showLoading({
          title: '正在加载',
          mask: true
        })
        app.globalData.util.request({
          url: 'entry/wxapp/AddCar',
          cachetime: '0',
          data: {
            money: i.dn_money,
            good_id: i.good_id,
            store_id: r,
            user_id: that.isfqr ? e : that.zuid,
            son_id: that.isfqr ? '' : e,
            dr_id: that.isfqr ? '' : that.dr_id,
            num: 1,
            spec: n.toString(),
            combination_id: i.id,
            box_money: i.box_money,
            type: 2
          },
          success: function (t) {
            console.log(t)
            if ('1' == t.data) {
              for (var a = 0; a < o.length; a++) {
                for (var e = 0; e < o[a].good.length; e++) {
                  if (o[a].good[e].id == i.good_id) {
                    o[a].good[e].quantity++
                  }
                }
              }
              that.setData({
                dishes: o
              })
              that.gwcreload()
              that.setData({
                spggtoggle: true
              })
            }
            if ('超出库存!' == t.data) {
              uni.showModal({
                title: '提示',
                content: '暂无库存!请选择其他规格或商品'
              })
            }
          }
        })
      }
    },

    gwcreload: function () {
      var a = this.dishes
      var that = this
      var t = uni.getStorageSync('users').id
      var o = this.store_id
      console.log(a, t, o)
      app.globalData.util.request({
        url: 'entry/wxapp/MyCar',
        cachetime: '0',
        data: {
          store_id: o,
          user_id: that.isfqr ? t : that.zuid,
          son_id: that.isfqr ? '' : t,
          dr_id: that.isfqr ? '' : that.dr_id,
          type: 2
        },
        success: function (t) {
          console.log(t)
          console.log(a)
          that.setData({
            cart_list: t.data
          })
          that.subText()
        }
      })
    },

    gbspgg: function () {
      this.setData({
        spggtoggle: true
      })
    },

    gbyysj: function () {
      this.setData({
        yysjtoggle: true
      })
    },

    selectednavbar: function (t) {
      console.log(t)
      this.setData({
        selectedindex: t.currentTarget.dataset.index
      })
    },

    selectMenu: function (e) {
      var s = this.dishes
      var that = this
      var o = uni.getStorageSync('users').id
      var d = that.store_id
      var r = e.currentTarget.dataset.itemIndex
      console.log(s, o, d, r)
      this.setData({
        catalogSelect: e.currentTarget.dataset.itemIndex
      })
      if (0 == s[e.currentTarget.dataset.itemIndex].good.length) {
        var t = s[e.currentTarget.dataset.itemIndex].id
        console.log('还没加载过数据', t)
        that.setData({
          cpjzz: true
        })
        app.globalData.util.request({
          url: 'entry/wxapp/Dishes',
          cachetime: '0',
          data: {
            type_id: t,
            type: 1
          },
          success: function (t) {
            console.log(t.data)
            for (var a = 0; a < t.data.length; a++) {
              t.data[a].quantity = Number(t.data[a].quantity)
            }
            s[e.currentTarget.dataset.itemIndex].good = t.data
            that.setData({
              cpjzz: false
            })
            app.globalData.util.request({
              url: 'entry/wxapp/MyCar',
              cachetime: '0',
              data: {
                store_id: d,
                user_id: that.isfqr ? o : that.zuid,
                son_id: that.isfqr ? '' : o,
                dr_id: that.isfqr ? '' : that.dr_id,
                type: 2
              },
              success: function (t) {
                console.log(t)
                for (var a = t.data.res, e = 0; e < a.length; e++) {
                  for (var o = 0; o < s[r].good.length; o++) {
                    if (a[e].good_id == s[r].good[o].id) {
                      s[r].good[o].quantity =
                        s[r].good[o].quantity + Number(a[e].num)
                    }
                  }
                }
                console.log(s)
                that.setData({
                  dishes: s
                })
              }
            })
          }
        })
      } else {
        console.log('已有缓存数据')
      }
    },

    swiperChange: function (t) {
      console.log(t)
      this.setData({
        selectedindex: t.detail.current
      })
    },

    showcart: function () {
      this.setData({
        share_modal_active: !this.share_modal_active
      })
    },

    closecart: function () {
      this.setData({
        share_modal_active: false
      })
    },

    clear: function () {
      var that = this
      var s = this.dishes
      var a = uni.getStorageSync('users').id
      var e = that.store_id
      console.log(s, a, e)
      uni.showModal({
        title: '提示',
        content: '确定清空此商家的购物车吗？',
        success: function (t) {
          if (t.confirm) {
            console.log('用户点击确定')
            uni.showLoading({
              title: '正在加载',
              mask: true
            })
            app.globalData.util.request({
              url: 'entry/wxapp/DelCar',
              cachetime: '0',
              data: {
                store_id: e,
                user_id: that.isfqr ? a : that.zuid,
                son_id: that.isfqr ? '' : a,
                dr_id: that.isfqr ? '' : that.dr_id,
                type: 2
              },
              success: function (t) {
                console.log(t.data)
                if ('1' == t.data) {
                  for (var a = 0; a < s.length; a++) {
                    for (var e = 0; e < s[a].good.length; e++) {
                      s[a].good[e].quantity = 0
                    }
                  }
                  that.setData({
                    dishes: s,
                    share_modal_active: false
                  })
                  that.gwcreload()
                }
              }
            })
          } else {
            if (t.cancel) {
              console.log('用户点击取消')
            }
          }
        }
      })
    },

    subText: function () {
      console.log(this)
      var t
      var a = parseFloat(this.cart_list.money)
      var e = parseFloat(this.start_at)
      console.log(a, e)
      if (a <= 0) {
        t = '还没有选购商品'
      } else {
        console.log(a)
        t = '去结算'
      }
      this.setData({
        subtext: t
      })
    },

    maketel: function (t) {
      var a = this.store.tel
      uni.makePhoneCall({
        phoneNumber: a
      })
    },

    location: function () {
      var t = this.store.coordinates.split(',')
      var a = this.store
      console.log(t)
      uni.openLocation({
        latitude: parseFloat(t[0]),
        longitude: parseFloat(t[1]),
        address: a.address,
        name: a.name
      })
    },

    pjmore: function () {
      console.log('上拉加载', this.pagenum)
      this.mygd ||
        !this.jzgd ||
        this.isjzz ||
        (this.setData({
          jzgd: false
        }),
        this.getstorelist())
    },

    trueFun() {
      console.log('占位：函数 true 未声明')
    }
  }
}
</script>
<style>
@import './smdcxgsp.css';
</style>
